<?php
/**
 * Created by PhpStorm.
 * User: sunfan
 * Date: 2017/8/8
 * Time: 10:36
 */

namespace Common\Model;


use Think\Model;

class BrandModel extends Model
{

    protected $_validate = array(
        array('name','require','品牌名必填'),
        array('logo','require','logo 必传'),
    );

    // 添加
    public function store(){
        if($this->create()){
           $data = I('post.');
           $data['create_time'] = date("Y-m-d H:i:s");
           if($add = $this->add($data)) return $add;
           $this->error = "添加失败";
        }
      return false;
    }

    //  编辑
    public function update(){
        if($this->create()){

            $data = I('post.',array());
            $id = $data['id']?$data['id']:0;
            unset($data['id']);
            if($add = $this->where(array('id'=>$id))->save($data)) return $add;
            $this->error = "请修改再提交";
        }
        return false;
    }
}